<?php
//入库查询
class GetOutStoreApp extends MallbaseApp
{
	function index()
	{
		$data = array();
		$CKCode = empty($_REQUEST['CKCode']) ? '' : trim($_REQUEST['CKCode']);
		$TiLink = empty($_REQUEST['TiLink']) ? '' : trim($_REQUEST['TiLink']);
		$pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
		$Godown = empty($_REQUEST['Godown']) ? '' : trim($_REQUEST['Godown']);
		//$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';

        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
		if ($this->checkUrl(WEB_SERVICE2)) {
			$client = new soapclient(WEB_SERVICE2);
			$client->soap_defencoding = 'utf-8';
			$client->decode_utf8 = false;
			$client->xml_encoding = 'utf-8';
			$param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","CKCode":"' . $CKCode . '","TiLink":"' . $TiLink . '","Godown":"' . $Godown . '","wxNum": "' . $wxNum . '"}');

			$result = $client->__Call("GetOutStore", array($param));

			if (is_soap_fault($result)) {
				trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
			} else {
				$result = json_decode(json_encode($result->GetOutStoreResult), TRUE);
				$result = json_decode($result, true);
				if ($result['status'] == 1) {
					$data = $result['result'];
					$dataCount = $result['dataCount'];
				} else {
					if ($result['result'] == '该用户未登录') {
						echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
						echo "<script>alert('请先绑定微信'); window.location.href='index.php?app=login&hist=getoutstore&wxNum=".$wxNum."'; </script>  ";
						exit();
                    } elseif (strstr($result['result'], '该用户无权')) {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
                        echo "<script>alert('$result[result]'); window.location.href='index.php?app=menu'; </script>  ";
                        exit();
					}
				}

			}
		}
		$this->import_resource(array('script' => 'jquery.ui/jquery.ui.js,jquery.ui/i18n/' . i18n_code() . '.js',
            'style' => 'jquery.ui/themes/ui-lightness/jquery.ui.css'));
		if ($data) {
			$this->assign('getoutstores', $data);
			$page = $this->_get_page();
			$page['item_count'] = $dataCount;
			$this->_format_pageweb($page);
			$this->assign('page_info', $page);
		}
		$this->display('getoutstore.index.html');
	}

	//明细
	function detail()
	{
		$key = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
		$data = array();
		$pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
		$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        /*$wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='index.php?app=login'; </script>  ";//使用weixin.php的页面
        }*/
		if ($this->checkUrl(WEB_SERVICE2)) {
			$client = new soapclient(WEB_SERVICE2);
			$client->soap_defencoding = 'utf-8';
			$client->decode_utf8 = false;
			$client->xml_encoding = 'utf-8';
			$param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","key":"' . $key . '","wxNum": "' . $wxNum . '"}');
			$result = $client->__Call("GetOutStoreMX", array($param));
			if (is_soap_fault($result)) {
				trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
			} else {
				$result = json_decode(json_encode($result->GetOutStoreMXResult), TRUE);
                $result = preg_replace('/([\r\n])/', '', $result);
				$result = json_decode($result, true);
				if ($result['status'] == 1) {
					$data = $result['result'];
					$dataCount = $result['dataCount'];
					if ($data) {
						foreach ($data as $k => $val) {
							$data[$k]['SOM_TId'] = $key;
						}
					}


				}

			}
		}
		if ($data) {
			$this->assign('getoutstores', $data);
			$page = $this->_get_page();
			$page['item_count'] = $dataCount;
			$this->_format_pageweb($page);
			$this->assign('page_info', $page);
		}
		$this->display('getoutstore.detail.html');
	}

	//列表更多
	function listmore()
	{
		$SOM_TId = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
		$data = array();
		$pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
		$CKCode = empty($_REQUEST['CKCode']) ? '' : trim($_REQUEST['CKCode']);
		$TiLink = empty($_REQUEST['TiLink']) ? '' : trim($_REQUEST['TiLink']);
		$Godown = empty($_REQUEST['Godown']) ? '' : trim($_REQUEST['Godown']);
		$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        /*$wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='index.php?app=login'; </script>  ";//使用weixin.php的页面
        }*/
		if ($this->checkUrl(WEB_SERVICE2)) {
			$client = new soapclient(WEB_SERVICE2);
			$client->soap_defencoding = 'utf-8';
			$client->decode_utf8 = false;
			$client->xml_encoding = 'utf-8';
			$param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","CKCode":"' . $CKCode . '","TiLink":"' . $TiLink . '","Godown":"' . $Godown . '","wxNum": "' . $wxNum . '"}');
			$result = $client->__Call("GetOutStore", array($param));
			if (is_soap_fault($result)) {
				trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
			} else {
				$result = json_decode(json_encode($result->GetOutStoreResult), TRUE);
                $result = preg_replace('/([\r\n])/', '', $result);
				$result = json_decode($result, true);

				if ($result['status'] == 1) {
					foreach ($result['result'] as $key => $val) {
						if ($val['SOM_TId'] == $SOM_TId) {
							$data = $val;
							break;
						}
					}
				}


			}
		}
		if ($data) {
			$this->assign('getoutstore', $data);
		}
		$this->display('getoutstore.listmore.html');
	}

	//明细更多
	function infomore()
	{
		$key = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
		$SOS_Tid = isset($_REQUEST['tid']) ? trim($_REQUEST['tid']) : '';
		$pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
		$data = array();
		$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        /*$wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='index.php?app=login'; </script>  ";//使用weixin.php的页面
        }*/
		if ($this->checkUrl(WEB_SERVICE2)) {
			$client = new soapclient(WEB_SERVICE2);
			$client->soap_defencoding = 'utf-8';
			$client->decode_utf8 = false;
			$client->xml_encoding = 'utf-8';
			$param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","key":"' . $key . '","wxNum": "' . $wxNum . '"}');
			$result = $client->__Call("GetOutStoreMX", array($param));
			if (is_soap_fault($result)) {
				trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
			} else {
				$result = json_decode(json_encode($result->GetOutStoreMXResult), TRUE);
                $result = preg_replace('/([\r\n])/', '', $result);
				$result = json_decode($result, true);
				if ($result['status'] == 1) {
					foreach ($result['result'] as $k => $val) {
						if ($val['SOS_Tid'] == $SOS_Tid) {
							$data = $val;
							break;
						}
					}
				} else {

                    echo "<script>alert('".$result['result']."'); </script>  ";
                }

			}
		}
		if ($data) {
			$this->assign('getoutstore', $data);
		}
		$this->display('getoutstore.infomore.html');
	}

    //调用快递100
    function express()
    {
        $data = array();
        $com = empty($_REQUEST['com']) ? '' : trim($_REQUEST['com']);
        $num = empty($_REQUEST['num']) ? '' : trim($_REQUEST['num']);
        //查询的快递公司的编码
        $com = "ems";
        //查询的快递单号
        $num = "9744069922432";
        if($com && $num) {
            $post_data = array();
            $post_data["customer"] = 'DFC6BC952FA064D0379D22E0E1A854F8';
            $key = 'YOuhrZpZ1074';
            $post_data["param"] = '{"com":"' . $com . '","num":"' . $num . '","from":"","to":""}';
            $url = 'https://poll.kuaidi100.com/poll/query.do';
            $post_data["sign"] = md5($post_data["param"] . $key . $post_data["customer"]);
            $post_data["sign"] = strtoupper($post_data["sign"]);
            $o = "";
            foreach ($post_data as $k => $v) {
                $o .= "$k=" . urlencode($v) . "&";        //默认UTF-8编码格式
            }
            $post_data = substr($o, 0, -1);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $result = curl_exec($ch);
            curl_close($ch);
            $data = str_replace("\"", '"', $result);
            $data = json_decode($data, true);
            if($data['message']=='ok'){
                if($data['state']){
                    $data['state_str'] = $this->get_status($data['state']);
                }
                if($data['com']){
                    $data['com_str'] = $this->get_com($data['com']);
                }
            }
        }
        $this->assign('data',$data);
        $this->display('getoutstore.express.html');

	}
}